package org.keyyond.ms.scheduler.service.impl;

import org.keyyond.ms.core.util.HttpUtil;
import org.keyyond.ms.scheduler.service.EcDataSyncService;
import org.keyyond.ms.scheduler.util.EncryptUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

@Service
@RefreshScope
public class EcDataSyncServiceImpl implements EcDataSyncService {

	@Value("${authParam}")
	private String authParam;
	
	@Value("${esbPrefix}")
	private String esbPrefix;

	private static Logger logger = LoggerFactory
			.getLogger(MsEsbFeiYunSyncServiceImpl.class);

	@Override
	public String doSendOrganizationToEc(String relationApp) {
		// TODO Auto-generated method stub
		String param = "{\"relationApp\":\"" + relationApp + "\"}";
		String encrypt = EncryptUtil.encrypt2(authParam, param);
		String result = null;
		if (encrypt != null) {
			result = HttpUtil.sendPost(
					esbPrefix+"esb_org/sendDepartment", encrypt,
					"UTF-8");
		} else {
			logger.info("加密异常！");
		}
		return result;
	}

	@Override
	public String doSendPostToEc(String relationApp) {
		// TODO Auto-generated method stub
		String param = "{\"relationApp\":\"" + relationApp + "\"}";
		String encrypt = EncryptUtil.encrypt2(authParam, param);
		String result = null;
		if (encrypt != null) {
			result = HttpUtil.sendPost(
					esbPrefix+"esb_org/sendPost", encrypt,
					"UTF-8");
		} else {
			logger.info("加密异常！");
		}
		return result;
	}

	@Override
	public String doSendPersonnelToEc(String relationApp) {
		// TODO Auto-generated method stub
		String param = "{\"relationApp\":\"" + relationApp + "\"}";
		String encrypt = EncryptUtil.encrypt2(authParam, param);
		String result = null;
		if (encrypt != null) {
			result = HttpUtil.sendPost(
					esbPrefix+"esb_org/sendStructure", encrypt,
					"UTF-8");
		} else {
			logger.info("加密异常！");
		}
		return result;
	}

}
